package ddk

import (
	"errors"

	"gitee.com/ddlin/openpdd/core"
	"gitee.com/ddlin/openpdd/model"
)

// GoodsPromotionQueryRequest 多多进宝信息流渠道备案授权素材上传接口 API Request
type GoodsPromotionQueryRequest struct {
	// GoodsID 商品GoodsId
	GoodsID uint64 `json:"goods_id,omitempty"`
	//mall_id
	MallID uint64 `json:"mall_id,omitempty"`
	//page_number
	PageNumber uint64 `json:"page_number,omitempty"`
	//page_size
	PageSize uint64 `json:"page_size,omitempty"`
}

// GetType implement Request interface
func (r GoodsPromotionQueryRequest) GetType() string {
	return "pdd.ddk.promotion.goods.query"
}

// Application GoodsPromotionQueryResponse.Application
type Application struct {
	//comment 审核信息
	Comment string `json:"comment,omitempty"`
	//goods_id 商品id
	GoodsID uint64 `json:"goods_id,omitempty"`
	//mall_id 店铺id
	MallID uint64 `json:"mall_id,omitempty"`
	//status 报备状态，0-已创建，1-已提交，2-已通过，3-已驳回
	Status             uint64 `json:"status,omitempty"`
	PromotionEndTime   int64  `json:"promotion_end_time,omitempty"`
	PromotionStartTime int64  `json:"promotion_start_time,omitempty"`
}

// GoodsPromotionQueryResponse 多多进宝信息流投放商品报备进度查询 API Response
type GoodsPromotionQueryResponse struct {
	model.CommonResponse
	Response struct {
		// ApplicationList
		ApplicationList []Application `json:"application_list,omitempty"`
		//total
		Total uint64 `json:"total,omitempty"`
	} `json:"response"`
}

type count struct {
	//total
}

// GoodsPromotionQuery 多多进宝信息流投放商品报备进度查询
func GoodsPromotionQuery(clt *core.SDKClient, req *GoodsPromotionQueryRequest) ([]Application, uint64, error) {
	var resp GoodsPromotionQueryResponse
	if err := clt.Do(req, &resp, ""); err != nil {
		return nil, 0, err
	}
	// if GoodsPromotionRightAuthResponse.Response empty
	if resp.Response.ApplicationList == nil {
		return nil, 0, errors.New("GoodsPromotionRightAuthResponse.Response empty")
	}
	return resp.Response.ApplicationList, resp.Response.Total, nil
}
